import React from 'react';
import { Button, message } from 'antd';
import { AudioOutlined, RobotOutlined } from '@ant-design/icons';
import { useVoiceInput, useVoiceAssistant } from '@/hooks/app-bridge-hooks';

interface VoiceControlsProps {
  onVoiceInputResult?: (text: string) => void;
  className?: string;
}

const VoiceControls: React.FC<VoiceControlsProps> = ({ 
  onVoiceInputResult,
  className = ''
}) => {
  const { 
    startVoiceInput, 
    isListening, 
    isAvailable: isVoiceInputAvailable 
  } = useVoiceInput();
  
  const { 
    activateAssistant, 
    isActive: isAssistantActive,
    isAvailable: isAssistantAvailable 
  } = useVoiceAssistant();

  const handleVoiceInputClick = async () => {
    if (!isVoiceInputAvailable) {
      message.warning('语音输入功能仅在安卓App中可用');
      return;
    }

    try {
      const text = await startVoiceInput({
        maxDuration: 10, // 10 seconds max
        language: 'zh-CN',
        prompt: '请说话...'
      });
      
      if (text && onVoiceInputResult) {
        onVoiceInputResult(text);
      }
    } catch (error) {
      message.error('语音输入失败');
      console.error('Voice input error:', error);
    }
  };

  const handleVoiceAssistantClick = async () => {
    if (!isAssistantAvailable) {
      message.warning('小安语音助手功能仅在安卓App中可用');
      return;
    }

    try {
      await activateAssistant({
        fullScreen: true,
        theme: 'light'
      });
    } catch (error) {
      message.error('启动语音助手失败');
      console.error('Voice assistant error:', error);
    }
  };

  return (
    <div className={`flex items-center gap-3 ${className}`}>
      <Button
        type="primary"
        icon={<AudioOutlined />}
        onClick={handleVoiceInputClick}
        loading={isListening}
        shape="circle"
        size="large"
        title="语音转文字"
      />
      
      <Button
        type="primary"
        icon={<RobotOutlined />}
        onClick={handleVoiceAssistantClick}
        loading={isAssistantActive}
        shape="circle"
        size="large"
        title="小安语音助手"
      />
    </div>
  );
};

export default VoiceControls;
